﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.iRods.Common;

namespace Renci.iRods.Data
{
    public class Token : DataItem
    {
        [iRodsColumn(DataObjectAttributes.COL_TOKEN_ID)]
        public long ID { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_TOKEN_NAMESPACE)]
        public string Namespace { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_TOKEN_NAME)]
        public string Name { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_TOKEN_VALUE)]
        public string Value { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_TOKEN_VALUE2)]
        public string Value2 { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_TOKEN_VALUE3)]
        public string Value3 { get; internal set; }

        [iRodsColumn(DataObjectAttributes.COL_TOKEN_COMMENT)]
        public string Comment { get; internal set; }

        internal Token(IRodsConnection connection)
            : base(connection)
        {

        }

        internal Token(IRodsConnection connection, string namespaceName, string name)
            : base(connection)
        {
            this.Namespace = namespaceName;
            this.Name = name;
        }

        public override void Refresh()
        {
            this.Exists = this.Load((q) =>
            {
                q.AddCondition(DataObjectAttributes.COL_TOKEN_NAMESPACE, string.Format("='{0}'", this.Namespace));
                q.AddCondition(DataObjectAttributes.COL_TOKEN_NAME, string.Format("='{0}'", this.Name));
            });
        }
    }
}
